<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../rurple.css" type="text/css" />

<title>Amazing - part 3</title>
</head>
<body>
<h2 class="title">19. Amazing - part 3</h2>

<p>As you should have noticed the program doesn't work. What happens is that
Reeborg gets in an infinite loop when there is no wall around him. We need to
have him <tt>move()</tt> after turning right, as indicated below:</p>

<pre>
<span class="keyword">def</span> turn_right():
    repeat(turn_left, 3)

put_beeper()
move()
<span class="keyword">while not</span> on_beeper():
    <span class="keyword">if</span> right_is_clear():
        turn_right()
        move()
    <span class="keyword">elif</span> front_is_clear():
        move()
    <span class="keyword">else</span>:
        turn_left()

turn_off()
</pre>

<!--================================================-->
<hr class="line" />

<h3 class="section">More complicated world</h3>

<p>Now, consider the world illustrated below. Will our program work?</p>

<p><img alt="around the world: start" src=
"../../images/intro/around3start.png" /></p>

<p>As you probably guessed, unfortunately the answer is no. 
Try to figure out why before reading any further.</p>

<div class="lessons_nav">
<a href="18-amazing2.htm"><img alt="previous" src=
"../../images/previous.png" /> Amazing - part2</a> - <a href=
"../lessons_toc.htm"><img alt="home" src="../../images/home.png" /></a> - <a href=
"20-amazing4.htm">Amazing - part 4 <img alt="next" src=
"../../images/next.png" /></a>
</div>
</body>
</html>
